import { BaseEntity } from '@libs/common/entities';
import { ApiProperty } from '@nestjs/swagger';
import { Dayjs } from '@shencom/utils-date';
import { Transform } from 'class-transformer';
import { Column, Entity, Index } from 'typeorm';

@Entity('crm_node_hr_performance')
@Index('userId_date', ['userId', 'date'], { unique: true })
@Index('dingId_date', ['dingId', 'date'], { unique: true })
export class Performance extends BaseEntity {
  @ApiProperty({ description: '钉钉 id', type: String })
  @Column({ comment: '钉钉 id' })
  dingId: String;

  @ApiProperty({ description: 'userid', type: String })
  @Column({ comment: 'userid' })
  userId: String;

  @ApiProperty({ description: '用户名', type: String })
  @Column({ comment: '用户名' })
  name: String;

  @ApiProperty({ description: '绩效时间', type: Date })
  @Transform(({ type, value }) => {
    if (!value) return;
    if (type === 0) {
      return Dayjs(value).toDate();
    }

    return Dayjs(value).valueOf();
  })
  @Column('date', { comment: '绩效时间' })
  date: Date;

  @ApiProperty({ description: '绩效总分', type: Number })
  @Column('double', { comment: '绩效总分', nullable: true })
  score?: Number;

  @ApiProperty({ description: '考勤分', type: Number })
  @Column('double', { comment: '考勤分', nullable: true })
  attendance?: Number;

  @ApiProperty({ description: '责任态度', type: Number })
  @Column('double', { comment: '责任态度', nullable: true })
  attitude?: Number;

  @ApiProperty({ description: '工作质量', type: Number })
  @Column('double', { comment: '工作质量', nullable: true })
  quality?: Number;

  @ApiProperty({ description: '工作效率', type: Number })
  @Column('double', { comment: '工作效率', nullable: true })
  efficiency?: Number;

  @ApiProperty({ description: '团队协作', type: Number })
  @Column('double', { comment: '团队协作', nullable: true })
  teamwork?: Number;
}
